﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Mrsoft.Controls
{
    public partial class MrProgressBar : Nothing
    {
        public MrProgressBar()
        {
            InitializeComponent();
        }
        // 绘制边框与否
        // 边框Color
        // 绘制文本
        private string _text = "ProgressBar";
        private Color _textColor = Color.Snow;
        private int _min = 0;
        private int _max = 100;
        private int _value = 0;

        public string TextStr { set { _text = value; this.Invalidate(); } get { return _text; } }
        public Color TextColor { set { _textColor = value; this.Invalidate(); } get { return _textColor; } }
        public int Max { set { _max = value;  } get { return _max; } }
        public int Min { set { _min = value; } get { return _min; } }
        public int Value { set { _value = value; this.Invalidate(); } get { return _value; } }
        //
        private void MrProgressBar_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(new Pen(Color.FromArgb(128, this.ForeColor)), 0, 0, this.Width - 1, this.Height - 1);
            SolidBrush br = new SolidBrush(this.ForeColor);
            if (_max > 0)
            {
                e.Graphics.FillRectangle(br, 0, 0, this.Width * _value / _max, this.Height);
            }
            if (!string.IsNullOrEmpty(_text))
            {
                br.Color = _textColor;
                e.Graphics.DrawString(_text, this.Font, br, new PointF(5, (float)this.Height / 2 - (float)this.Font.Height / 2));
            }
            br.Dispose();
            e.Dispose();
        }
    }
}
